<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*
 * 用于合肥32中更新学生卡号
*/

class Realcard extends BaseController {

	public function __construct() {
        parent::__construct();
        // // 后台初始化方法
        // $this->admin_init();
        // 加载类库
        $this->load->model('schoolModel');
        $this->load->model('classesModel');
        $this->load->model('contentModel');
        $this->load->model('dataModel');
    }

    public function index() {
        // 获取学校信息
        $schoolInfo = $this->schoolModel->get_school_info_by_name('合肥市第三十二中学');
        if(empty($schoolInfo)) {
            throw new Exception('学校不存在');
        }
        $studentName = $this->get('student_name');
        $studentNum = $this->get('student_num');
        $cardnum =  $this->get('cardnum');
        if(empty($cardnum)) {
            throw new Exception('卡号参数不能为空');
        }
        $studentInfo = $this->schoolModel->get_student_info_by_realname($studentName, $schoolInfo['id'], 0, $studentNum);
        if(empty($studentInfo)) {
            throw new Exception('找不到该学生');
        }
        $this->db->update(SchoolModel::$schoolStudentTable, array(
            'realcard' => $cardnum,
            'updatetime' => date('Y-m-d H:i:s')
        ), array(
            'id' => $studentInfo['id']
        ));
        exit(json('更新卡号成功', true));
    }
}